package com.shop.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DButils {
	private final static String driver="com.mysql.jdbc.Driver";
	private final static String url="jdbc:mysql://localhost:3306/rx-shop";
	private final static String user="root";
	private final static String pwd="123456";
	static {
		try {
			Class.forName(driver); 
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		try {
			Connection conn=DriverManager.getConnection(url,user,pwd);
			return conn;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		}
	

	public static void close(Connection conn, ResultSet  rs, PreparedStatement ps) {
		
			try {
				if(rs!=null) {
				rs.close();
				}
				if(ps!=null) {
					ps.close();
					}
				if(conn!=null) {
					conn.close();
					}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	}
}

	